// pages/wofang/wofang.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    flist:[],
    clist:[],
    dlist:[],
    movableImg:'',
    index:0,
    page:0,
    showyc:false,
    showjj:false,
    showrj:false,
    showpaper:false,
    text:''

  },
  onclick1:function(){
    var showyc = this.data.showyc;
    this.setData({
      showyc:!showyc
    });
    var that =this;
    wx.request({
      url: 'http://localhost:8080/yichu',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          clist:res.data
        })
      }
    })

  },
  onclick2:function(){
    var showjj = this.data.showjj;
    this.setData({
      showjj:!showjj
    });
    var that = this;
    wx.request({
      url: 'http://localhost:8080/jiajv',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          flist:res.data
        })
      }
    });

  },
  onclick3:function(){
    var showrj = this.data.showrj;
    this.setData({
      showrj:!showrj
    });
    var that = this;
    wx.request({
      url: 'http://localhost:8080/riji',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        
        that.setData({
          dlist:res.data
        })
      }
    });
    var dlist = this.data.dlist;
    console.log(dlist);
    var page = this.data.page;
    var diary = dlist[page];
    console.log(diary);
    this.setData({
      diary:diary
    })

  },
  pre:function(){
    var page = this.data.page;
    var diary = this.data.dlist[page-1];
    this.setData({
      page:page - 1,
      diary:diary
    })
  },
  next:function(){
    var page = this.data.page;
    var diary = this.data.dlist[page+1];
    this.setData({
      page:page + 1,
      diary:diary
    })
  },
  clickjj:function(e){
    var index = e.currentTarget.dataset.index;
    console.log(index);
    var flist = this.data.flist;
    var img = flist[index].img;
    this.setData({
      movableImg:img
    });
    

  },
  input:function(e){
    this.setData({
       text:e.detail.value
    });

  },
  clickBtn:function(){
    var text = this.data.text;
    console.log(text);
    wx.request({
      url: 'http://localhost:8080/writeDiary',
      data:{
        text:text

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        
      }
    });


  },
  write:function(){
    this.setData({
      showpaper:true
    })

  },
  close:function(){
      this.setData({
        showpaper:false
      })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/jiajv',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          flist:res.data
        })
      }
    });

    wx.request({
      url: 'http://localhost:8080/yichu',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          clist:res.data
        })
      }
    });

    
    wx.request({
      url: 'http://localhost:8080/riji',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        
        that.setData({
          dlist:res.data
        })
      }
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})